#include"tcpsocket.hpp"
#include<string>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<stdlib.h>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
using namespace std;


int main(int argc,char*argv[])
{

  //客户端虽然不用主动绑定地址信息，但是必须知道服务端地址
  if(argc < 3)
  {
    cout<< "usage: arg error \n";
    cout <<"\t ./tcp.cli  192.168.124.2 9000\n";
    return -1;
  }
  int srv_port =stoi(argv[2]);
  string srv_ip = argv[1];

  //搭建客户端
  //实例化一个对象
  TcpSocket sock;
  //1.创建套接字
  CHECK_RET(sock.Socket());
  //2.向服务端发起连接请求
  CHECK_RET(sock.Connect(srv_ip,srv_port));
  //3.循环发起数据
  while(1)
  {
    string data;
    cout << "client input:";
    fflush(stdout);
    cin >> data;
   CHECK_RET(sock.Send(data));
   
   data.clear();
   CHECK_RET(sock.Recv(&data));
   cout << "server response" << data << endl;


  }
  //关闭套接字
  sock.Close();
  return 0;
}
